﻿/**
* Copyright (c) 2010 Tony Zhou (http://www.cnblogs.com/zhouto/)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
* version: jquery.DynamicMessage.js on 12/15/2010 9:30am
**/
;
(function(jQuery) {
    $.fn.extend({
        DynamicMessage: function(options) {
            var settings = { message: "", delay: 1000, autoRemove: true, target: null };
            $.extend(settings, options);          
            this.addClass("Warning").bind("focus", function() {
                if ($(this).hasClass("Warning"))
                    $(this).removeClass("Warning");
            });
            if (settings.target == null) {
                if (this.attr("type") == "text") {
                    var new_obj = $("<div class='dynamicMessage'></div>").text(settings.message);
                }
                new_obj.css("position", "absolute")
                       .css("top", this.position().top + 2)
                       .css("left", this.position().left + this.width() + 10)
                       .appendTo(this.parent())
                       .show()
                       .delay(10000)
                       .hide(1000, function() {
                           $(this).remove();
                       });
            }
            else {
                var new_obj = $("<li></li>").text(settings.message);
                new_obj.appendTo($(settings.target))
                       .show()
                       .delay(10000)
                       .hide(1000, function() {
                           $(this).remove();
                       });
            }
        }

    });
})(jQuery);